<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class Monitor extends ActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function tableName()
	{
		return 'vh_monitor';
	}
	
	public function rules()
	{
		return array(
		);
	}

	public function search()
	{
		$condition = "";
                
		if(!empty($_POST['domain']))
			$condition .= " AND domain LIKE '%" . $_POST['domain'] . "%'";
                
		$query = "SELECT id, domain, alexaRank, rate, hyipNumber
                    FROM vh_monitor t
                    WHERE 1=1 $condition";
		
		$result = $this -> executeAllTotal($query);
	
		return $result;
	}
        
        public function getItem($id)
	{
            $query = '
                    SELECT *
                    FROM vh_monitor WHERE id = 
            ' . $id;
            
            $result = $this -> executeRow($query);

            return $result;
	}
        
        public function deleteMonitor($id)
        {
            $item = Monitor::model() -> findByPk($id);
             if ($item -> delete()) {
                 
                 $query = "DELETE FROM vh_hyip_monitor WHERE monitorID = :monitorID";
                 $this ->executeNone($query, array(":monitorID" => $id));
                 
                 return true;
             }
             else{
                 return false;
             }
        }
        
        public function getAllValue()
	{
            $query = "select id, domain from vh_monitor";
            $result = $this -> executeAll($query, array(), false);
            
            return $result;
	}
}